/*
Disclaimer of Warranty: THE PACKAGE IS PROVIDED
BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS'
AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT
ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF
THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


(c) Copyright 2013 Edward Principe
All Rights Reserved

*/
#include "stdafx.h"
#include <iostream>
#include <smtptr.h>
#include <debug.h>
#include <tchar.h>
#include "errrep.h"
#include "parse.h"
#include "parseall.h"

using namespace std;

void Print(ParseAll& parse, TokErr err);

//////////////////////////////////////////////////////////////////////////////////////
// RunTest: Runs a test
//////////////////////////////////////////////////////////////////////////////////////
extern "C" __declspec(dllexport) void RunTest()
{
	// Catch exceptions
	try
	{
		SmtPtr<ParseAll> parse; // The parser
		SmtPtr<TokEx> tokEx; // Used to translate error that's returned
		TokErr err; // Error

		// Deliminators
		parse->InitDelim();

		// Initlize buffer
		parse->InitBuffer(L"\"Hello World\" my name is \"Edward Principe\" + 6/87+(789>90)&3");

		// Parse
		while (true)
		{
			// Next word
			err = parse->Next();

			// At end?
			if (parse->IsEnd())
				break;

			// Print word
			Print(*parse,err);

		}

		// Print marker
		wcout << L"****" << endl;

		// Parse backwards
		while (true)
		{
			// Previous word
			err = parse->Prev();

			// At beginning?
			if (parse->IsBegin())
				break;

			// Print node
			Print(*parse, err);
		}

		// Return to OS
		return;
	}
	catch (InternalError *e)
	{
		wcerr << e->MakeMsg() << endl;
		e->Delete();
		return;
	}

}

//////////////////////////////////////////////////////////////////
// Print: Prints report for a word
//////////////////////////////////////////////////////////////////
void Print(ParseAll& parse, TokErr err)
{
	TokEx tokEx(err);

	wcout << L"Word: " << parse.GetWord() << endl;
    wcout << L"Error: " << tokEx.MakeMsg() << endl;
	wcout << L"IsString; " << parse.IsString() << endl;
}
